package com.lzh.others.basejava.Thread_21.bilibili_course_thread.CompletableFuturePrac_07;

import com.lzh.others.basejava.Thread_21.utils.SmallTool;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.IntStream;

/**
 * @author LiuZiHao
 * @date 创建时间:2023年05月22日 11:17:48
 */
public class CompletableFuturePrac_07_stream_api {
    public static void main(String[] args) {
        //设置最大线程数
        System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism","1");
        //查看 返回Java虚拟机可用的处理器数。
        System.out.println(Runtime.getRuntime().availableProcessors());
        //查看 当前线程数
        System.out.println(ForkJoinPool.commonPool().getPoolSize());
        //查看 最大线程数
        System.out.println(ForkJoinPool.getCommonPoolParallelism());


        SmallTool.printTimeAndThread("小白和小伙伴们 进餐厅点菜了");
        long startTime = System.currentTimeMillis();

        CompletableFuture[] dishes = IntStream.rangeClosed(1, 2)
                .mapToObj(i -> new Dish("菜" + i, 1))
                .map(dish -> CompletableFuture.runAsync(dish::make))
                .toArray(CompletableFuture[]::new);
        System.out.println(ForkJoinPool.commonPool().getPoolSize());

        CompletableFuture.allOf(dishes).join();
        SmallTool.printTimeAndThread("菜都做好了,上桌" + (System.currentTimeMillis() - startTime));

    }
}
